/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
#ifndef DRAWING_H_
#define DRAWING_H_

#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <png.h>
#include <pngconf.h>
#include <math.h>
#include <SDL/SDL.h>
#include <string>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include <png.h>
#include <SDL/SDL.h>
#include <math.h>
#include <string>
#endif
// Uncomment if want to use SDL_GFX when complete
// This should only be used if a computer doesn't have hardware acceleration, as it's very slow
// TODO: Implement
//#define USE_SDL

#define	FLOAT_TO_INT(in,out)		\
	__asm__ __volatile__ ("fistpl %0" : "=m" (out) : "t" (in) : "st") ; // This is a quick float to int variable, faster than regular casting
																		// It will work ONLY under x86 or x86_64 CPUs. It rounds, not trancutes//
struct tex{ // Custom Texture structure //
	GLuint Tex;
	int Width;
	int Height;
	// Information on how it was loaded
	int LoadType, R, G, B;
	char Filename[512];
};
extern bool NICE; 
extern int Height;
extern int Width;
int InitScreen(int _Width, int _Height);

//Text Drawing Functions
void DrawChar( int x, int y, char chr, int ww, int hh, float r, float g, float b, float a);
void DrawChar( int x, int y, int z, char chr, int ww, int hh, float r, float g, float b, float a);

void DrawString	(int x, int y, const char *string, int w, int h, float r, float g, float b,float a);
void DrawString	(int x, int y, const std::string string, int w, int h, float r, float g, float b, float a);
void DrawString	(int x, int y, const int string, int w, int h, float r, float g, float b, float a);
void DrawStringCenter(int x, int y, const char *string, int w, int h, float r, float g, float b, float a);
void DrawStringCenter(int x, int y, const std::string string, int w, int h, float r, float g, float b, float a);

//Primitive drawing
void DrawCircle(float x, float y, int radius, float r, float g, float b, float a);
void DrawBox(int x, int y, int ex, int ey, int r,int g, int b, int a);
void DrawBoxCenter(int x, int y, int width, int height, int r,int g, int b, int a);
void DrawPixel(int x, int y, int r,int g, int b, int a);
void DrawRect(int x, int y, int ex, int ey, unsigned int RGBA);
void DrawRect(int x, int y, int ex, int ey, int r,int g, int b, int a);
void DrawLine(float x,float y, float xx, float yy, int r,int g, int b, int a);
void DrawLine(float x,float y, float xx, float yy, int widthofline, int r,int g, int b, int a);

void BeginLine(float x, float y, int r, int g,int b,int a);
void EndLine(float x, float y);

//Texture Drawing
void DrawPic	(int x, int y, int w, int h, tex tmp);
void DrawPic	(float x, float y, float sx, float sy, float ex, float ey, float r, float g, float b, float a,int rr, tex tmp);
void DrawPicS	(float x, float y, float sx, float sy, float ex, float ey, float ww, float hh, int aa, tex tmp);
void DrawPicSR	(float x, float y, float sx, float sy, float ex, float ey, float ww, float hh, int aa, tex tmp);

//Texture Loading
tex LoadTexture		(const char *filename);
tex LoadTexture		(const char *filename, const int r, const int g, const int b);
tex LoadTextureA	(const char *filename);
void ClearScreen();
void Swap();
#endif
